package cn.anc.aonicardv.module.adpter.recorder;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.view.View;

import java.io.File;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import cn.anc.aonicardv.R;
import cn.anc.aonicardv.bean.FileBean;
import cn.anc.aonicardv.module.adpter.album.ThumbnailListAdapter;
import cn.anc.aonicardv.widget.SlideSelectView;
import cn.anc.httpcontrolutil.cache.CacheManager;

/**
 * Created by yangdai on 2017/5/19.
 */

public class RecorderThumbnailListAdapter extends ThumbnailListAdapter {

    public RecorderThumbnailListAdapter(Context context,List<? extends FileBean> fileBeanList, SlideSelectView slideSelectView) {
        super( context,fileBeanList, slideSelectView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final ViewHolder viewHolder = (ViewHolder) holder;
        if (slideSelectView.isUpdateItem(position)) {
            String cachePath = CacheManager.getCachePath(fileBeanList.get(slideSelectView.getRightItemPosition(position)).getPath());
            File file = new File(cachePath);
            viewHolder.thumbnailIv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onThumbnailListItemClickListener != null)
                        onThumbnailListItemClickListener.onItemClick(slideSelectView.getRightItemPosition(position));
                }
            });
            if (file.exists()) {
                viewHolder.thumbnailIv.setImageURI(Uri.fromFile(file));
            } else {
                viewHolder.thumbnailIv.setImageResource(R.mipmap.image_loading);
            }
        }
        else {
            viewHolder.thumbnailIv.setOnClickListener(null);
            viewHolder.thumbnailIv.setImageDrawable(new ColorDrawable(Color.WHITE));
        }
    }
}
